package com.atguigu.service;


import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.dao.MemberMapper;
import com.atguigu.pojo.MemberExample;
import com.atguigu.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService{

    @Autowired
    private MemberMapper memberMapper;
    @Override
    public List<Integer> countMembersByDate(List<String> dateList) throws Exception {
        List<Integer> countList= new ArrayList<Integer>();
        for (String date : dateList) {
            String date1 = DateUtils.getLastDayOfMonth(date);
            MemberExample example = new MemberExample();
            MemberExample.Criteria criteria = example.createCriteria();
            criteria.andRegtimeLessThanOrEqualTo(DateUtils.parseString2Date(date1));
            Long count = memberMapper.countByExample(example);
            countList.add(count.intValue());
        }
        return countList;
    }
}
